#include "bsp.h"
#include "cop_scheduler.h"
#include "stdio.h"

#include "canfestival_can.h"
#include "canfestival_timer.h"

	
// LED任务 500ms
void led_task(void)
{
    static uint8_t cnt = 0;
    
    cnt++;
    if(cnt % 2 == 0)
    {
        GPIO_ResetBits(GPIOF,GPIO_Pin_9);
    }
    else
    {
        GPIO_SetBits(GPIOF,GPIO_Pin_9);

    }


}


void task_init(void)
{
    // 初始化调度器时钟
    SCH_Init_Systick();

    // LED任务
    SCH_Add_Task(led_task,0,500); 

    // 启动调度器
    SCH_Start();
}

/* CANOPEN字典 */
extern CO_Data master_ObjDictData;

int main(void)
{
    
    // BSP初始化
    bsp_init();
	
    CANOpen_can_config();
    CANOpen_timer_config();
	
    setNodeId(&master_ObjDictData, 0x00);
    setState(&master_ObjDictData, Initialisation);	// Init the state
    setState(&master_ObjDictData,Pre_operational);
    setState(&master_ObjDictData, Operational);		// Put the master in operational mode
    

    printf("hello usart\n");


    // 任务初始化
    task_init();
	
    while(1)
    {
        SCH_Dispatch_Tasks();
    }


}


